package mvc.mapper;

import mvc.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import java.util.List;

public interface UserMapper {
    //全查
    @Select("select id,username,password,mailIndex from user")
    List<User> getUsers();

    //按userd的id查
    @Select("select id,username,password,mailIndex from user where id=#{id}")
    User getUserById(Integer id);

    //查username是否存在
    @Select("select username from user where username=#{username}")
    Integer getUserByName(String username);

    /*//按User添加
    @Insert("insert into user values(null,#{username},#{password},#{mailIndex}")
    Integer addUser(User u);*/

    //获得新增用户id的查询
    @Insert("insert into user values(null,#{username},#{password},#{mailIndex}")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    Integer addUserWithId(User u);

}
